package com.cn.mmd.controller;

import com.cn.mmd.model.Course;
import com.cn.mmd.model.CourseWeekly;
import com.cn.mmd.model.LogManage;
import com.cn.mmd.model.Student;
import com.cn.mmd.service.*;
import com.cn.mmd.tools.GetLimitNum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2016/8/2 0002.
 */
@Controller
@RequestMapping(value = "page/manageCourse")
public class ManageCourseController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private CourseWeeklyService courseWeeklyService;

    @Autowired
    private LogManageService logManageService;

    @Autowired
    private StudentGroupingService studentGroupingService;

    private GetLimitNum getLimitNum = new GetLimitNum();
    /**
     * 管理添加课程
     * @param request
     * @return
     */
    @RequestMapping(value = "/add")
    @ResponseBody public synchronized  Object manageCourseAdd(HttpServletRequest request){
        Map<String,Object> objectMap = new HashMap<String, Object>();
        Map<String,Object> map = new HashMap<String, Object>();
        String manageId = request.getParameter("manageId");
        String courseId = request.getParameter("courseId");
        String courseName = request.getParameter("courseName");
        String courseBeginEnd = request.getParameter("courseBeginEnd");
        Float courseCredit = Float.valueOf(request.getParameter("courseCredit"));
        String courseCollege = request.getParameter("courseCollege");
        String courseTime = request.getParameter("courseTime");
        String courseClassRoom = request.getParameter("courseClassRoom");
        String courseRequest = request.getParameter("courseRequest");
        String courseTeacher = request.getParameter("courseTeacher");
        String courseNature = request.getParameter("courseNature");
        String courseClasss = request.getParameter("courseClassS");
        String courseCollegeC = request.getParameter("courseCollegeC");
        if (courseService.selectByKey(courseId)==null){
            String [] strings = courseTime.split(";");
            String [] strings1 = courseClassRoom.split(";");
            int num=0;
            if (strings.length>strings1.length){
                num = strings.length;
            }else if (strings.length<strings1.length){
                num = strings1.length;
            }else {
                num = strings.length;
            }
            CourseWeekly  courseWeekly = new CourseWeekly();
            if (strings.length>1&&strings1.length==1){
                for (int i = 0 ; i < strings.length ; i++){
                    courseWeekly = new CourseWeekly();
                    String courseWeeklyDay = strings[i].substring(0,2);
                    String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                    String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                    String courseWeeklyClassRoom = courseClassRoom;
                    courseWeekly.setCourseid(courseId);
                    courseWeekly.setCourseweeklyday(courseWeeklyDay);
                    courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                    courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                    courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                    if (courseWeeklyService.selectByAll(courseWeekly)==null){//暂未进行精准的判断课程是否有同时间同地点的，和是否有1个老师在一时间上2堂课
                        map.put(courseWeeklyDay+courseWeeklyQuarter+courseWeeklyWeek+courseWeeklyClassRoom,courseWeekly);
                    }
                }
            }else if (strings.length==1&&strings1.length>1){
                for (int i = 0 ; i < strings1.length ; i++){
                    courseWeekly = new CourseWeekly();
                    String courseWeeklyDay = courseTime.substring(0,2);
                    String courseWeeklyQuarter = courseTime.split("第")[1].split("节")[0];
                    String courseWeeklyWeek = courseTime.split("第")[2].split("周")[0];
                    String courseWeeklyClassRoom = strings1[i];
                    courseWeekly.setCourseid(courseId);
                    courseWeekly.setCourseweeklyday(courseWeeklyDay);
                    courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                    courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                    courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                    if (courseWeeklyService.selectByAll(courseWeekly)==null){
                        map.put(courseWeeklyDay+courseWeeklyQuarter+courseWeeklyWeek+courseWeeklyClassRoom,courseWeekly);
                    }
                }
            }else if (strings.length>1&&strings1.length>1&&strings.length==strings1.length){
                for (int i = 0 ; i < strings.length ; i++){
                    courseWeekly = new CourseWeekly();
                    String courseWeeklyDay = strings[i].substring(0,2);
                    String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                    String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                    String courseWeeklyClassRoom = strings1[i];
                    courseWeekly.setCourseid(courseId);
                    courseWeekly.setCourseweeklyday(courseWeeklyDay);
                    courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                    courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                    courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                    if (courseWeeklyService.selectByAll(courseWeekly)==null){
                        map.put(courseWeeklyDay+courseWeeklyQuarter+courseWeeklyWeek+courseWeeklyClassRoom+","+i,courseWeekly);
                    }
                }
            }else if (strings.length>1&&strings1.length>1&&strings.length!=strings1.length){
                System.out.println(1);
                for (int i = 0 ; i < num ; i++){
                    courseWeekly = new CourseWeekly();
                    if (strings[i]!=null&&strings1[i]!=null) {
                        String courseWeeklyDay = strings[i].substring(0, 2);
                        String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                        String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                        String courseWeeklyClassRoom = strings1[i];
                        courseWeekly.setCourseid(courseId);
                        courseWeekly.setCourseweeklyday(courseWeeklyDay);
                        courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                        courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                        courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                        if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                            map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                        }
                    }else if (strings[i]==null&&strings1[i]!=null){
                        String courseWeeklyDay = strings[strings.length-1].substring(0, 2);
                        String courseWeeklyQuarter = strings[strings.length-1].split("第")[1].split("节")[0];
                        String courseWeeklyWeek = strings[strings.length-1].split("第")[2].split("周")[0];
                        String courseWeeklyClassRoom = strings1[i];
                        courseWeekly.setCourseid(courseId);
                        courseWeekly.setCourseweeklyday(courseWeeklyDay);
                        courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                        courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                        courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                        if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                            map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                        }
                    }else if (strings[i]!=null&&strings1[i]==null) {
                        String courseWeeklyDay = strings[i].substring(0, 2);
                        String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                        String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                        String courseWeeklyClassRoom = strings1[strings1.length-1];
                        courseWeekly.setCourseid(courseId);
                        courseWeekly.setCourseweeklyday(courseWeeklyDay);
                        courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                        courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                        courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                        if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                            map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                        }
                    }
                }
            }else if (strings.length==1&&strings1.length==1){
                System.out.println(1);
                String courseWeeklyDay = courseTime.substring(0, 2);
                String courseWeeklyQuarter = courseTime.split("第")[1].split("节")[0];
                String courseWeeklyWeek = courseTime.split("第")[2].split("周")[0];
                String courseWeeklyClassRoom = courseClassRoom;
                courseWeekly.setCourseid(courseId);
                courseWeekly.setCourseweeklyday(courseWeeklyDay);
                courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                    map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                }
            }
            Course course = new Course();
            course.setCourseid(courseId);
            course.setCourseteacher(courseTeacher);
            course.setCoursebeginend(courseBeginEnd);
            course.setCourseclassroom(courseClassRoom);
            course.setCourseclasss(courseClasss);
            course.setCoursecollege(courseCollege);
            course.setCoursecollegec(courseCollegeC);
            course.setCoursecredit(courseCredit);
            course.setCoursename(courseName);
            course.setCoursenature(courseNature);
            course.setCourserequest(courseRequest);
            course.setCoursetime(courseTime);
            if (map.size()==num) {
                if (courseService.insertSelective(course)> 0) {
                    Iterator iter = map.entrySet().iterator();
                    Map.Entry entry;
                    int k = 0;
                    for (; k < map.size(); k++) {
                        entry = (Map.Entry) iter.next();
                        courseWeekly =(CourseWeekly) entry.getValue();
                        courseWeeklyService.insertSelective(courseWeekly);
                    }
                    objectMap.put("code", 200);
                    objectMap.put("message", "成功");
                    Date date = new Date();
                    SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    String logTime = time.format(date);
                    LogManage logManage = new LogManage();
                    logManage.setLogtime(logTime);
                    logManage.setManageid(manageId);
                    logManage.setLogcontent("添加了一门课程:" + courseId);
                    logManageService.insertSelective(logManage);
                } else {
                    objectMap.put("code", 201);
                    objectMap.put("message", "添加失败");
                }
            }else {
                objectMap.put("code",203);
                objectMap.put("message","当前课程时间和其他课程冲突");
            }
        }else {
            objectMap.put("code",202);
            objectMap.put("message","此课程id已存在");
        }
        return objectMap;
    }

    /**
     * 管理查看课程 根据课程id 或课程名字或 课程老师
     * @param request
     * @return
     */
    @RequestMapping(value = "/select")
    @ResponseBody public synchronized  Object manageCourseSel(HttpServletRequest request){
        Map<String,Object> objectMap = new HashMap<String, Object>();
        List<Map> mapList = new ArrayList<Map>();
        Map<String,Object> map;
        String manageId = request.getParameter("manageId");
        Integer startrow = Integer.parseInt(request.getParameter("startrow"));
        Integer pageSize = Integer.parseInt(request.getParameter("pageSize"));
        String courseId = request.getParameter("courseId");
        Course course = new Course();
        course.setPageSize(pageSize);
        course.setStartrow(startrow);
        course.setCourseid(courseId);
        List<Course> courseList =courseService.selectByPaging(course);
        if (courseList!=null&&courseList.size()>0){
            for (int i  = 0 ; i < courseList.size() ; i++){
                map = new HashMap<String, Object>();
                course = courseList.get(i);
                map.put("courseTeacher", course.getCourseteacher());
                map.put("courseId", course.getCourseid());
                map.put("courseClassS", course.getCourseclasss());
                map.put("courseBeginEnd", course.getCoursebeginend());
                map.put("courseClassRoom", course.getCourseclassroom());
                map.put("courseCollect",course.getCoursecollect());
                map.put("courseCollege", course.getCoursecollege());
                map.put("courseCollegeC", course.getCoursecollegec());
                map.put("courseCredit", course.getCoursecredit());
                map.put("courseTime", course.getCoursetime());
                map.put("courseRequest", course.getCourserequest());
                map.put("courseNature", course.getCoursenature());
                map.put("courseName", course.getCoursename());
                mapList.add(map);
            }
            if (mapList!=null&&mapList.size()==courseList.size()){
                course = new Course();
                course.setCourseid(courseId);
                int i1 = courseService.countLimitNum(course);
                objectMap.put("total", i1);
                objectMap.put("page",getLimitNum.getLimitNum(i1,10));
                objectMap.put("code",200);
                objectMap.put("message","成功");
                objectMap.put("data",mapList);
            }else {
                objectMap.put("code",201);
                objectMap.put("message","查看失败");
                objectMap.put("total", 0);
            }
        }else {
            objectMap.put("code",202);
            objectMap.put("message","没有查到课程");
            objectMap.put("total", 0);
        }
        return objectMap;
    }

    /**
     * 修改单条信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/upd")
    @ResponseBody public synchronized  Object  manageCourseUpd(HttpServletRequest request){
        Map<String,Object> objectMap = new HashMap<String, Object>();
        Map<String,Object> map = new HashMap<String, Object>();
        String manageId = request.getParameter("manageId");
        String courseId = request.getParameter("courseId");
        String courseName = request.getParameter("courseName");
        String courseBeginEnd = request.getParameter("courseBeginEnd");
        Float courseCredit = Float.valueOf(request.getParameter("courseCredit"));
        String courseCollege = request.getParameter("courseCollege");
        String courseTime = request.getParameter("courseTime");
        String courseClassRoom = request.getParameter("courseClassRoom");
        String courseRequest = request.getParameter("courseRequest");
        String courseTeacher = request.getParameter("courseTeacher");
        String courseNature = request.getParameter("courseNature");
        String courseClasss = request.getParameter("courseClassS");
        String courseCollegeC = request.getParameter("courseCollegeC");
        if (courseService.selectByKey(courseId)!=null){
            String [] strings = courseTime.split(";");
            String [] strings1 = courseClassRoom.split(";");
            int num=0;
            if (strings.length>strings1.length){
                num = strings.length;
            }else if (strings.length<strings1.length){
                num = strings1.length;
            }else {
                num = strings.length;
            }
            CourseWeekly  courseWeekly = new CourseWeekly();
            if (strings.length>1&&strings1.length==1){
                for (int i = 0 ; i < strings.length ; i++){
                    courseWeekly = new CourseWeekly();
                    String courseWeeklyDay = strings[i].substring(0,2);
                    String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                    String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                    String courseWeeklyClassRoom = courseClassRoom;
                    courseWeekly.setCourseid(courseId);
                    courseWeekly.setCourseweeklyday(courseWeeklyDay);
                    courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                    courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                    courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                    if (courseWeeklyService.selectByAll(courseWeekly)==null){//暂未进行精准的判断课程是否有同时间同地点的，和是否有1个老师在一时间上2堂课
                        map.put(courseWeeklyDay+courseWeeklyQuarter+courseWeeklyWeek+courseWeeklyClassRoom,courseWeekly);
                    }
                }
            }else if (strings.length==1&&strings1.length>1){
                for (int i = 0 ; i < strings1.length ; i++){
                    courseWeekly = new CourseWeekly();
                    String courseWeeklyDay = courseTime.substring(0,2);
                    String courseWeeklyQuarter = courseTime.split("第")[1].split("节")[0];
                    String courseWeeklyWeek = courseTime.split("第")[2].split("周")[0];
                    String courseWeeklyClassRoom = strings1[i];
                    courseWeekly.setCourseid(courseId);
                    courseWeekly.setCourseweeklyday(courseWeeklyDay);
                    courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                    courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                    courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                    if (courseWeeklyService.selectByAll(courseWeekly)==null){
                        map.put(courseWeeklyDay+courseWeeklyQuarter+courseWeeklyWeek+courseWeeklyClassRoom,courseWeekly);
                    }
                }
            }else if (strings.length>1&&strings1.length>1&&strings.length==strings1.length){
                for (int i = 0 ; i < strings.length ; i++){
                    courseWeekly = new CourseWeekly();
                    String courseWeeklyDay = strings[i].substring(0,2);
                    String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                    String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                    String courseWeeklyClassRoom = strings1[i];
                    courseWeekly.setCourseid(courseId);
                    courseWeekly.setCourseweeklyday(courseWeeklyDay);
                    courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                    courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                    courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                    if (courseWeeklyService.selectByAll(courseWeekly)==null){
                        map.put(courseWeeklyDay+courseWeeklyQuarter+courseWeeklyWeek+courseWeeklyClassRoom+","+i,courseWeekly);
                    }
                }
            }else if (strings.length>1&&strings1.length>1&&strings.length!=strings1.length){
                System.out.println(1);
                for (int i = 0 ; i < num ; i++){
                    courseWeekly = new CourseWeekly();
                    if (strings[i]!=null&&strings1[i]!=null) {
                        String courseWeeklyDay = strings[i].substring(0, 2);
                        String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                        String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                        String courseWeeklyClassRoom = strings1[i];
                        courseWeekly.setCourseid(courseId);
                        courseWeekly.setCourseweeklyday(courseWeeklyDay);
                        courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                        courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                        courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                        if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                            map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                        }
                    }else if (strings[i]==null&&strings1[i]!=null){
                        String courseWeeklyDay = strings[strings.length-1].substring(0, 2);
                        String courseWeeklyQuarter = strings[strings.length-1].split("第")[1].split("节")[0];
                        String courseWeeklyWeek = strings[strings.length-1].split("第")[2].split("周")[0];
                        String courseWeeklyClassRoom = strings1[i];
                        courseWeekly.setCourseid(courseId);
                        courseWeekly.setCourseweeklyday(courseWeeklyDay);
                        courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                        courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                        courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                        if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                            map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                        }
                    }else if (strings[i]!=null&&strings1[i]==null) {
                        String courseWeeklyDay = strings[i].substring(0, 2);
                        String courseWeeklyQuarter = strings[i].split("第")[1].split("节")[0];
                        String courseWeeklyWeek = strings[i].split("第")[2].split("周")[0];
                        String courseWeeklyClassRoom = strings1[strings1.length-1];
                        courseWeekly.setCourseid(courseId);
                        courseWeekly.setCourseweeklyday(courseWeeklyDay);
                        courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                        courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                        courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                        if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                            map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                        }
                    }
                }
            }else if (strings.length==1&&strings1.length==1){
                System.out.println(1);
                String courseWeeklyDay = courseTime.substring(0, 2);
                String courseWeeklyQuarter = courseTime.split("第")[1].split("节")[0];
                String courseWeeklyWeek = courseTime.split("第")[2].split("周")[0];
                String courseWeeklyClassRoom = courseClassRoom;
                courseWeekly.setCourseid(courseId);
                courseWeekly.setCourseweeklyday(courseWeeklyDay);
                courseWeekly.setCourseweeklyweek(courseWeeklyWeek);
                courseWeekly.setCourseweeklyclassroom(courseWeeklyClassRoom);
                courseWeekly.setCourseweeklyquarter(courseWeeklyQuarter);
                if (courseWeeklyService.selectByAll(courseWeekly) == null) {
                    map.put(courseWeeklyDay + courseWeeklyQuarter + courseWeeklyWeek + courseWeeklyClassRoom, courseWeekly);
                }
            }
            Course course = new Course();
            course.setCourseid(courseId);
            course.setCourseteacher(courseTeacher);
            course.setCoursebeginend(courseBeginEnd);
            course.setCourseclassroom(courseClassRoom);
            course.setCourseclasss(courseClasss);
            course.setCoursecollege(courseCollege);
            course.setCoursecollegec(courseCollegeC);
            course.setCoursecredit(courseCredit);
            course.setCoursename(courseName);
            course.setCoursenature(courseNature);
            course.setCourserequest(courseRequest);
            course.setCoursetime(courseTime);
            if (map.size()==num) {
                if (courseService.updateByPrimaryKeySelective(course) > 0) {
                    Iterator iter = map.entrySet().iterator();
                    Map.Entry entry;
                    for (int k = 0; k < map.size(); k++) {
                        entry = (Map.Entry) iter.next();
                        courseWeeklyService.updateByPrimaryKeySelective((CourseWeekly) entry.getValue());
                    }
                    objectMap.put("code", 200);
                    objectMap.put("message", "成功");
                    Date date = new Date();
                    SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    String logTime = time.format(date);
                    LogManage logManage = new LogManage();
                    logManage.setLogtime(logTime);
                    logManage.setManageid(manageId);
                    logManage.setLogcontent("修改了一门课程:" + courseId);
                    logManageService.insertSelective(logManage);
                } else {
                    objectMap.put("code", 201);
                    objectMap.put("message", "修改失败");
                }
            }else {
                objectMap.put("code",203);
                objectMap.put("message","当前课程时间地址和其他课程冲突");
            }
        }else {
            objectMap.put("code",202);
            objectMap.put("message","此课程不存在");
        }
        return objectMap;
    }

    /**
     * 删除一门课程
     * @param request
     * @return
     */
    @RequestMapping(value = "/delOne")
    @ResponseBody public synchronized  Object  manageCourseDelOne(HttpServletRequest request) {
        Map<String, Object> objectMap = new HashMap<String, Object>();
        String manageId = request.getParameter("manageId");
        String courseId = request.getParameter("courseId");
        if (courseService.deleteByPrimaryKey(courseId)>0){
            courseWeeklyService.deleteByCouId(courseId);
            studentGroupingService.deleteByTeaId(courseId);
            studentGroupingService.deleteByTeaIdG(courseId);
            objectMap.put("code", 200);
            objectMap.put("message", "成功");
            Date date = new Date();
            SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String logTime = time.format(date);
            LogManage logManage = new LogManage();
            logManage.setLogtime(logTime);
            logManage.setManageid(manageId);
            logManage.setLogcontent("删除了一门课程:" + courseId);
            logManageService.insertSelective(logManage);
        }else {
            objectMap.put("code", 201);
            objectMap.put("message", "删除失败");
        }
        return objectMap;
    }
}
